import libmedia_codec
import numpy
video_decoder = libmedia_codec.H264Decoder()    # h264编码器


# h264编码
def h264_decode(data):
    res_frame_list = []
    frames = video_decoder.decode(data)
    for frame_data in frames:
        (frame, width, height, ls) = frame_data
        if frame:
            frame = numpy.fromstring(frame, dtype=numpy.ubyte, count=len(frame), sep='')
            frame = (frame.reshape((height, width, 3)))
            res_frame_list.append(frame)
    return res_frame_list


